package com.databasefunction;

import java.awt.List;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import com.commonfunction.CommFunction;
import com.mysql.jdbc.Statement;

public class AllDBFunction {
	DatabaseConnection database_connection = new DatabaseConnection();
    
	public void createTableUsers(Connection connection) {

		String url = DatabaseConstants.DB_URL;
		Statement stmt = null;
		System.out.println("above try");
		try {
			stmt = (Statement) connection.createStatement();
			System.out.println("statement start");
			String sql = "CREATE TABLE IF NOT EXISTS userInfo" + "("
					+ DatabaseConstants.userName + " VARCHAR(255), " + " "
					+ DatabaseConstants.password + " TEXT, " + " "
					+ DatabaseConstants.role + " TEXT, " + " "
					+ DatabaseConstants.fullName + " TEXT, " + " "
					+ DatabaseConstants.address + " TEXT, " + " "
					+ DatabaseConstants.contact + " TEXT, " + " "
					+ DatabaseConstants.emailId + " TEXT, " + " "
					+ DatabaseConstants.securityQuestion1 + " TEXT, " + " "
					+ DatabaseConstants.securityAnswer1 + " TEXT, " + " "
					+ DatabaseConstants.securityQuestion2 + " TEXT, " + " "
					+ DatabaseConstants.securityAnswer2 + " TEXT, " + " "
					+ DatabaseConstants.date + " INT,"
					+ " CONSTRAINT unique_id_constraint UNIQUE ("
					+ DatabaseConstants.userName + ")) ";
			System.out.println(sql);
			stmt.executeUpdate(sql);
			System.out.println("table check");

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}// end finally try

	}

	public boolean insertTableUsers(String uName, 
			String fullName, String address, String contact, String emailId,
			String securityQuestion1, String securityAns1,
			String securityQuestion2, String securityAns2) {
		
		boolean dataBool = true;
		int response = 0;
		Statement stmt = null;

		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "UPDATE userInfo " + "SET "
					+ DatabaseConstants.fullName + " ='" + fullName + "', "
					+ DatabaseConstants.address + " = '" + address + "',"
					+ DatabaseConstants.contact + " ='" + contact + "', "
					+ DatabaseConstants.emailId + " ='" + emailId + "', "
					+ DatabaseConstants.securityQuestion1 + " ='" + securityQuestion1 + "', "
					+ DatabaseConstants.securityAnswer1 + " ='" + securityAns1 + "', "
					+ DatabaseConstants.securityQuestion2 + " ='" + securityQuestion2 + "', "
					+ DatabaseConstants.securityAnswer2 + " ='" + securityAns2 + "' "
					+ " where " + DatabaseConstants.userName + " = '"
					+ uName + "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			// STEP 5: Extract data from result set

			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			System.out.println("asdfgh" + dataBool);
			return dataBool;

		}
		System.out.println(dataBool);
		return dataBool;
	}
	

	public List getuserlist(String initials){
		List list = new List();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from userInfo where "
					+ DatabaseConstants.userName + " LIKE '" + initials
					+ "%'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name
				list.add(rs.getString(DatabaseConstants.userName));

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return list;

		}
		for (int i = 0; i < list.getItemCount(); i++) {
			System.out.println(list.getItem(i) + " ");
		}

		return list;
		
		
	}
	/*
	 * 
	 * */

	public String getrole(String user, String pass) {
		String role = "";
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select role from userInfo where userName = '" + user
					+ "' and password = '" + pass + "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);

			// STEP 5: Extract data from result set
			while (rs.next()) {
				// Retrieve by column name

				role = rs.getString(DatabaseConstants.role);
				System.out.print(", role: " + role);

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return "Invalid";

		}
		System.out.println(role);
		return role;
	}

	public boolean isuserexist(String user) {
		boolean isuserexists = false;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from userInfo where userName = '" + user
					+ "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name

				isuserexists = true;

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;

		}
		System.out.println(isuserexists);
		return isuserexists;
	}

	public HashMap getAllUserList() {
		HashMap hm = new HashMap();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

				try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from userInfo";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name
				HashMap hashMap = new HashMap();
				hashMap.put("username", rs.getString(DatabaseConstants.userName));
				hashMap.put("password", rs.getString(DatabaseConstants.password));
				hashMap.put("role", rs.getString(DatabaseConstants.role));
				hm.put(rs.getString(DatabaseConstants.userName), hashMap);
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return hm;

		}

		return hm;
		
		
		
	}

	public boolean deleteUser(String user) {
		boolean dataBool = false;
		int response = 0;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "DELETE FROM userInfo where "
					+ DatabaseConstants.userName + " = '" + user + "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			return dataBool;

		}
		System.out.println(dataBool);
		return dataBool;

	}

	public boolean addUser(String user, String pass, String role) {
		boolean dataBool = false;
		int response = 0;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "INSERT INTO userInfo " + "VALUES ('" + user + "','"
					+ pass + "','" + role + "','','','','','','','','',0)";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			if (response == 0) {
				dataBool = false;
			}
			System.out.println("data inserted successfully");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			dataBool = false;

			e.printStackTrace();
			return dataBool;
		}

		return dataBool;

	}

	public HashMap securitytype(String user) {
		HashMap hm = new HashMap();
		Statement stmt = null;
		String securityQuestion1 = "";
		String securityQuestion2 = "";
		String securityanswer1 = "";
		String securityanswer2 = "";
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from userInfo where userName = '" + user
					+ "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name
				securityQuestion1 = rs
						.getString(DatabaseConstants.securityQuestion1);
				securityanswer1 = rs
						.getString(DatabaseConstants.securityAnswer1);
				securityQuestion2 = rs
						.getString(DatabaseConstants.securityQuestion2);
				securityanswer2 = rs
						.getString(DatabaseConstants.securityAnswer2);
				hm.put("question1", securityQuestion1);
				hm.put("ans1", securityanswer1);
				hm.put("question2", securityQuestion2);
				hm.put("ans2", securityanswer2);
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return hm;

		}

		return hm;
	}

	public boolean saveCredentials(String originaluser, String newuser,
			String password) {
		boolean dataBool = true;
		int response = 0;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "UPDATE userInfo " + "SET "
					+ DatabaseConstants.userName + " ='" + newuser + "', "
					+ DatabaseConstants.password + " = '" + password + "'"
					+ " where " + DatabaseConstants.userName + " = '"
					+ originaluser + "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			// STEP 5: Extract data from result set

			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			System.out.println("asdfgh" + dataBool);
			return dataBool;

		}
		System.out.println(dataBool);
		return dataBool;
	}

	// //database tables and functions of admin their role security questions
	// ends here...............

	// //database tables and functions for broker commision agent and customer
	// starts here ...............
	public void createTableAddDealers(Connection connection) {
		String dbname = "parvati_database";
		connection = database_connection.getConnection(dbname);

		Statement stmt = null;
		try {
			stmt = (Statement) connection.createStatement();
			System.out.println("statement start");
			String sql = "CREATE TABLE IF NOT EXISTS dealerInfo" + "("
					+ DatabaseConstants.dealername + " VARCHAR(255) UNIQUE, "
					+ " " + DatabaseConstants.dealerrole + " TEXT, " + " "
					+ DatabaseConstants.dealerUniqueid + " VARCHAR(255), "
					+ " " + DatabaseConstants.dealeraddress + " TEXT, " + " "
					+ DatabaseConstants.dealercity + " TEXT, " + " "
					+ DatabaseConstants.dealerdistrict + " TEXT, " + " "
					+ DatabaseConstants.dealerstate + " TEXT, " + " "
					+ DatabaseConstants.dealercountry + " TEXT, " + " "
					+ DatabaseConstants.dealerzipcode + " TEXT, " + " "
					+ DatabaseConstants.dealercontact + " TEXT, " + " "
					+ DatabaseConstants.dealeremailid + " TEXT, " + " "
					+ DatabaseConstants.dealerdate + " INT,"
					+ " CONSTRAINT unique_id_constraint PRIMARY KEY ("
					+ DatabaseConstants.dealerUniqueid + ")) ";
			System.out.println(sql);
			stmt.executeUpdate(sql);
			System.out.println("table check");

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("error");
			e.printStackTrace();
		}// end finally try

	}

	public boolean isdealerexists(String dealer) {
		boolean isdealerexists = false;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from dealerInfo where "+DatabaseConstants.dealername+" = '" +dealer+ "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name

				isdealerexists = true;

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;

		}
		System.out.println(isdealerexists);
		return isdealerexists;
	}
	
	
	public String getUniqueId() {

		String uniqueId = UUID.randomUUID().toString().replaceAll("-", "")
				.substring(0, 6);

		if (isUniqueIdPresent(uniqueId)) {

			uniqueId = getUniqueId();
		}

		return uniqueId;
	}

	private boolean isUniqueIdPresent(String uniqueId) {
		Statement stmt1 = null;
		boolean res = false;

		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {

			stmt1 = (Statement) connection.createStatement();

			String sqlquery = "select " + DatabaseConstants.dealerUniqueid
					+ " from dealerInfo";
			System.out.println(sqlquery);
			ResultSet rs = stmt1.executeQuery(sqlquery);
			// STEP 5: Extract data from result set
			while (rs.next()) {

				if (uniqueId == rs.getNString(DatabaseConstants.dealerUniqueid)) {

					res = true;
				}

			}
			rs.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			res = false;
			e.printStackTrace();
			return res;
		}
		return res;
	}

	public boolean submitdata(String name, String role, String address,
			String city, String district, String state, String country,
			String zipcode, String contact, String emailid, int date) {

		boolean res = true;
		int response = 0;

		Statement stmt = null;
		String uniqueId = "";
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();
			uniqueId = getUniqueId();

			if (uniqueId != "") {

				String sql = "INSERT INTO dealerInfo " + "VALUES ('" + name
						+ "','" + role + "','" + uniqueId + "','" + address
						+ "','" + city + "','" + district + "','" + state
						+ "','" + country + "','" + zipcode + "','" + contact
						+ "','" + emailid + "'," + date + ")";
				System.out.println(sql);
				response = stmt.executeUpdate(sql);
				if (response == 0) {
					res = false;
				}

				// System.out.println("data inserted successfully");

			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			res = false;
			System.out.println(res);
			return false;
		}
		return res;

	}

	public String getaddress(String user) {
		String address = "";
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		Statement stmt = null;
		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from dealerInfo where "
					+ DatabaseConstants.dealername + " = '" + user + "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set
			while (rs.next()) {
				// Retrieve by column name

				address = rs.getString(DatabaseConstants.address) + ","
						+ rs.getString(DatabaseConstants.dealercity) + ", "
						+ rs.getString(DatabaseConstants.dealerdistrict) + ", "
						+ rs.getString(DatabaseConstants.dealerstate) + ".";

				System.out.print(", address: " + address);

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return "Invalid";

		}

		return address;
	}
	public boolean isCityOrDistPresent(String name,int cityordist){
		boolean databool=false;
		Statement stmt = null;
		ResultSet rs;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

	try {
			if (cityordist==DatabaseConstants.CITY){
				stmt = (Statement) connection.createStatement();

				String sql = "select * from dealerInfo where "
						+ DatabaseConstants.dealercity +"='"+name+"'";
				System.out.println(sql);
				rs = stmt.executeQuery(sql);
				while (rs.next()) {
					// Retrieve by column name
					databool=true;

				}
				rs.close();
			}
			else{
				
				stmt = (Statement) connection.createStatement();

				String sql = "select * from dealerInfo where "
						+ DatabaseConstants.dealerdistrict +"='"+name+"'";
				System.out.println(sql);
				rs = stmt.executeQuery(sql);
				while (rs.next()) {
					// Retrieve by column name
					databool=true;

				}
				rs.close();
			}
			
			// STEP 5: Extract data from result set
			
		} catch (Exception e) {
			e.printStackTrace();
			databool=false;
			//return databool;

		}
		
		
		return databool;
	}
	public List getCustmer(String initials, String role) {

		List list = new List();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from dealerInfo where "
					+ DatabaseConstants.dealername + " LIKE '" + initials
					+ "%' and " + DatabaseConstants.dealerrole + " = '" + role
					+ "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name
				list.add(rs.getString(DatabaseConstants.dealername));

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return list;

		}
		for (int i = 0; i < list.getItemCount(); i++) {
			System.out.println(list.getItem(i) + " ");
		}

		return list;

	}

	// database tables and functions for broker commision agent and customer
	// ends here ...............
	// DATABASE FOR barcodeFinalTable functions starts
	// here................................

	public void createTableBarcodeFinal(Connection connection) {
		String dbname = "parvati_database";
		connection = database_connection.getConnection(dbname);

		Statement stmt = null;
		try {
			stmt = (Statement) connection.createStatement();
			System.out.println("statement start");
			String sql = "CREATE TABLE IF NOT EXISTS barcodeFinal" + "("
					+ DatabaseConstants.barcodeNumber + " VARCHAR(255), " + " "
					+ DatabaseConstants.barcodeBrokerName + " TEXT, " + " "
					+ DatabaseConstants.barcodecustomerName + " TEXT, " + " "
					+ DatabaseConstants.barcodeCommisionAgentName + " TEXT, "
					+ DatabaseConstants.barcodeaddress + " TEXT, "
					+ " " + DatabaseConstants.barcodeRstNo + " TEXT, " + " "
					+ DatabaseConstants.barcodeVehicleNo + " TEXT, " + " "
					+ DatabaseConstants.barcodeCommodity + " TEXT, " + " "
					+ DatabaseConstants.barcodeNoOfBags + " TEXT, " + " "
					+ DatabaseConstants.barcodePONo + " TEXT, " + " "
					+ DatabaseConstants.barcodeGrossWeight + " TEXT, " + " "
					+ DatabaseConstants.barcodeTareWeight + " TEXT, " + " "
					+ DatabaseConstants.barcodeNetWeight + " TEXT," + " "
					+ DatabaseConstants.barcodedate + " INT, " + " "
					+ DatabaseConstants.barcodetime + " TEXT, " + " "
					+ DatabaseConstants.barcodeDamageSeeds + " TEXT, " + " "
					+ DatabaseConstants.barcodeSandSilica + " TEXT, " + " "
					+ DatabaseConstants.barcodeMoisture + " TEXT, " + " "
					+ DatabaseConstants.barcodeExcessDamage + " TEXT, " + " "
					+ DatabaseConstants.barcodeExcessSandSilica + " TEXT, "
					+ " " + DatabaseConstants.barcodeExcessMoisture + " TEXT, "
					+ " " + DatabaseConstants.barcodeDamageAmountCut
					+ " TEXT, " + " "
					+ DatabaseConstants.barcodeSandSilicaAmountCut + " TEXT, "
					+ " " + DatabaseConstants.barcodeMoistureAmountCut
					+ " TEXT, " + " " + DatabaseConstants.barcodeRate
					+ " TEXT, " + " " + DatabaseConstants.barcodeGrossAmount
					+ " TEXT, " + " " + DatabaseConstants.barcodeLessRebate
					+ " TEXT, " + " " + DatabaseConstants.barcodeUnloading
					+ " TEXT, " + " " + DatabaseConstants.barcodecashDiscount
					+ " TEXT, " + " " + DatabaseConstants.barcodeAdvance
					+ " TEXT," + " " + DatabaseConstants.barcodeAddDalali
					+ " TEXT, " + " " + DatabaseConstants.barcodeTotalRebate
					+ " TEXT, " + " " + DatabaseConstants.barcodeTotalPaid
					+ " TEXT, " + " " + DatabaseConstants.barcodeHide
					+ " TEXT, " + " "
					+ DatabaseConstants.barcodeWeighingMachineUser + " TEXT, "
					+ " " + DatabaseConstants.barcodeLabUser + " TEXT, "
					+ " CONSTRAINT barcode_constraint PRIMARY KEY ("
					+ DatabaseConstants.barcodeNumber + ")) ";
			System.out.println(sql);
			stmt.executeUpdate(sql);
			System.out.println("table check barcodeFinal");

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("error");
			e.printStackTrace();
		}// end finally try

	}

	public boolean isBarcodeExists(String code) {
		boolean isBarcodeExists = false;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from barcodeFinal where "
					+ DatabaseConstants.barcodeNumber + " = '" + code + "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name

				isBarcodeExists = true;

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return isBarcodeExists;

		}
		System.out.println(isBarcodeExists);

		return isBarcodeExists;
	}

	public boolean isBarcodeExistsInAnalysis(String code) {
		boolean isBarcodeExists = false;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from analysisreporttable where "
					+ DatabaseConstants.ANALYSIS_BARCODE_COLUMN + " = '" + code + "'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name

				isBarcodeExists = true;

			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return isBarcodeExists;

		}
		System.out.println(isBarcodeExists);

		return isBarcodeExists;
	}

	public HashMap getDataAgainstSearch(String searchText, String serchBy,
			int startDate, int endDate, String searchDealer,
			String serchDealerBusiness) {
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		HashMap hm2 = new HashMap();
		boolean isDateFieldNull = true;
		Statement stmt = null;
		Statement stmt1 = null;
		ResultSet rs = null;
		ResultSet rs1 = null;
		String sql = "";
		String sql1 = "";

		if (startDate == 0 && endDate == 0) {
			isDateFieldNull = false;
		}

		try {
			stmt = (Statement) connection.createStatement();
			sql = "select * from dealerInfo where " + searchDealer + " = '"
					+ searchText + "'";
			System.out.println(sql);
			rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set
			while (rs.next()) {
				// Retrieve by column name
				HashMap hm = new HashMap();	
				hm.put("dataName", rs.getString(DatabaseConstants.dealername));
				hm.put("dataUniqueId",
						rs.getString(DatabaseConstants.dealerUniqueid));
				hm.put("dataAddress",
						rs.getString(DatabaseConstants.dealeraddress));
				hm.put("dataCity", rs.getString(DatabaseConstants.dealercity));
				hm.put("dataDistrict",
						rs.getString(DatabaseConstants.dealerdistrict));
				hm.put("dataState", rs.getString(DatabaseConstants.dealerstate));
				hm.put("dataCountry",
						rs.getString(DatabaseConstants.dealercountry));
				hm.put("dataZipcode",
						rs.getString(DatabaseConstants.dealerzipcode));
				hm.put("dataContact",
						rs.getString(DatabaseConstants.dealercontact));
				hm.put("dataEmailId",
						rs.getString(DatabaseConstants.dealeremailid));

				hm2.put("dealerData", hm);

			}
			rs.close();

			if (!isDateFieldNull) {
				stmt1 = (Statement) connection.createStatement();
				sql1 = "select * from barcodeFinal where "
						+ serchDealerBusiness + " = '" + searchText + "' ORDER BY "+DatabaseConstants.barcodedate +" DESC";
				System.out.println(sql1);
				rs1 = stmt1.executeQuery(sql1);
			} else if (startDate == 0) {

				stmt1 = (Statement) connection.createStatement();
				sql1 = "select * from barcodeFinal where "
						+ serchDealerBusiness + " = '" + searchText + "' "
						+ "AND " + DatabaseConstants.barcodedate + " <= "
						+ endDate + "  ORDER BY "+DatabaseConstants.barcodedate +" DESC";
				System.out.println(sql1);
				rs1 = stmt1.executeQuery(sql1);

			} else if (endDate == 0) {

				stmt1 = (Statement) connection.createStatement();
				sql1 = "select * from barcodeFinal where "
						+ serchDealerBusiness + " = '" + searchText + "' "
						+ "AND " + DatabaseConstants.barcodedate + " >= "
						+ startDate + "  ORDER BY "+DatabaseConstants.barcodedate +" DESC";
				System.out.println(sql1);
				rs1 = stmt1.executeQuery(sql1);

			} else {
				stmt1 = (Statement) connection.createStatement();
				sql1 = "select * from barcodeFinal where "
						+ serchDealerBusiness + " = '" + searchText + "' "
						+ "AND (" + DatabaseConstants.barcodedate + " BETWEEN "
						+ startDate + " AND " + endDate + ")  ORDER BY "+DatabaseConstants.barcodedate +" DESC";
				System.out.println(sql1);
				rs1 = stmt1.executeQuery(sql1);

			}

			// STEP 5: Extract data from result set
			while (rs1.next()) {
				// Retrieve by column name
				HashMap hm1 = new HashMap();
				hm1.put("businessBrokerName",
						rs1.getString(DatabaseConstants.barcodeBrokerName));
				hm1.put("businesscustomerName",
						rs1.getString(DatabaseConstants.barcodecustomerName));
				hm1.put("businessCommisionAgentName", rs1
						.getString(DatabaseConstants.barcodeCommisionAgentName));
				hm1.put("businessRSTNo",
						rs1.getString(DatabaseConstants.barcodeRstNo));
				hm1.put("businessVehicleNo",
						rs1.getString(DatabaseConstants.barcodeVehicleNo));
				hm1.put("businessCommodity",
						rs1.getString(DatabaseConstants.barcodeCommodity));
				hm1.put("businessNoOfBags",
						rs1.getString(DatabaseConstants.barcodeNoOfBags));
				hm1.put("businessPONo",
						rs1.getString(DatabaseConstants.barcodePONo));
				hm1.put("businessGrossWeight",
						rs1.getString(DatabaseConstants.barcodeGrossWeight));
				hm1.put("businessTareWeight",
						rs1.getString(DatabaseConstants.barcodeTareWeight));
				hm1.put("businessNetWeight",
						rs1.getString(DatabaseConstants.barcodeNetWeight));
				hm1.put("businessdate",
						rs1.getInt(DatabaseConstants.barcodedate));

				hm1.put("businessDamageSeeds",
						rs1.getString(DatabaseConstants.barcodeDamageSeeds));
				hm1.put("businessSandSilica",
						rs1.getString(DatabaseConstants.barcodeSandSilica));
				hm1.put("businessMoisture",
						rs1.getString(DatabaseConstants.barcodeMoisture));
				hm1.put("businessExcessDamage",
						rs1.getString(DatabaseConstants.barcodeExcessDamage));
				hm1.put("businessExcessSandSilica", rs1
						.getString(DatabaseConstants.barcodeExcessSandSilica));
				hm1.put("businessExcessMoisture",
						rs1.getString(DatabaseConstants.barcodeExcessMoisture));
				hm1.put("businessDamageAmountCut",
						rs1.getString(DatabaseConstants.barcodeDamageAmountCut));
				hm1.put("businessSandSilicaAmountCut",
						rs1.getString(DatabaseConstants.barcodeSandSilicaAmountCut));
				hm1.put("businessMoistureAmountCut", rs1
						.getString(DatabaseConstants.barcodeMoistureAmountCut));
				hm1.put("businessUnloading",
						rs1.getString(DatabaseConstants.barcodeUnloading));
				hm1.put("businessAddDalali",
						rs1.getString(DatabaseConstants.barcodeAddDalali));
				hm1.put("businessHide",
						rs1.getString(DatabaseConstants.barcodeHide));

				hm1.put("businessRate",
						rs1.getString(DatabaseConstants.barcodeRate));
				hm1.put("businessGrossAmount",
						rs1.getString(DatabaseConstants.barcodeGrossAmount));
				hm1.put("businessLessRebate",
						rs1.getString(DatabaseConstants.barcodeLessRebate));
				hm1.put("businesscashDiscount",
						rs1.getString(DatabaseConstants.barcodecashDiscount));
				hm1.put("businessAdvance",
						rs1.getString(DatabaseConstants.barcodeAdvance));

				hm1.put("businessTotalRebate",
						rs1.getString(DatabaseConstants.barcodeTotalRebate));
				hm1.put("businessTotalPaid",
						rs1.getString(DatabaseConstants.barcodeTotalPaid));
				hm1.put("businessWeighingMachineUser",
						rs1.getString(DatabaseConstants.barcodeWeighingMachineUser));
				hm1.put("businessLabUser",
						rs1.getString(DatabaseConstants.barcodecashDiscount));

				hm2.put(rs1.getString(DatabaseConstants.barcodeNumber), hm1);
			}
			rs1.close();

		} catch (Exception e) {
			e.printStackTrace();
			return null;

		}

		return hm2;
	}

	public List getcityordist(String searchtext,String searchby){
		List list = new List();
		Statement stmt = null;
		ResultSet rs;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

	try {
			if (searchby.equals("city")) {
				stmt = (Statement) connection.createStatement();

				String sql = "select * from dealerInfo where "
						+ DatabaseConstants.dealercity + " LIKE '" + searchtext+"%'";
				System.out.println(sql);
				rs = stmt.executeQuery(sql);
				while (rs.next()) {
					// Retrieve by column name
					
					list.add(rs.getString(DatabaseConstants.dealercity));

				}
				rs.close();
			}
			else{
				
				
				stmt = (Statement) connection.createStatement();

				String sql = "select * from dealerInfo where "
						+ DatabaseConstants.dealerdistrict + " LIKE '" + searchtext+"%'";
				System.out.println(sql);
				rs = stmt.executeQuery(sql);
				while (rs.next()) {
					// Retrieve by column name
					list.add(rs.getString(DatabaseConstants.dealerdistrict));

				}
				rs.close();
			}
			
			// STEP 5: Extract data from result set
			
		} catch (Exception e) {
			e.printStackTrace();
			return list;

		}
		for (int i = 0; i < list.getItemCount(); i++) {
			System.out.println(list.getItem(i) + " ");
		}

		
		return list;
		
		
	}
	
	
	public HashMap getDealerData(String searchText, String serchBy,
			int startDate, int endDate) {
		HashMap hm = new HashMap();

		boolean isDateFieldNull = true;

		switch (serchBy) {
		case "broker":

			hm = getDataAgainstSearch(searchText, serchBy, startDate, endDate,
					DatabaseConstants.dealername,
					DatabaseConstants.barcodeBrokerName);

			break;

		case "commisionagent":
			hm = getDataAgainstSearch(searchText, serchBy, startDate, endDate,
					DatabaseConstants.dealername,
					DatabaseConstants.barcodeCommisionAgentName);
			break;

		case "customer":
			hm = getDataAgainstSearch(searchText, serchBy, startDate, endDate,
					DatabaseConstants.dealername,
					DatabaseConstants.barcodecustomerName);
			break;

		case "city":

			hm = getDataAgainstCityDistrict(searchText, serchBy, startDate,
					endDate, "city");

			break;
		case "district":
			hm = getDataAgainstCityDistrict(searchText, serchBy, startDate,
					endDate, "district");
			break;

		default:
			break;
		}

		return hm;

	}

	
	public HashMap getDataAgainstCityDistrict(String searchText,
			String serchBy, int startDate, int endDate, String string) {
		// TODO Auto-generated method stub
		
		
		HashMap hm2 = new HashMap();
		boolean isDateFieldNull = true;
		Statement stmt = null;
		Statement stmt1 = null;
		ResultSet rs = null;
		ResultSet rs1 = null;
		String sql = "";
		String sql1 = "";

		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		List list = new List();

		if (startDate == 0 && endDate == 0) {
			isDateFieldNull = false;
		}

		try {

			if (string == "city") {
				stmt = (Statement) connection.createStatement();
				sql = "select * from dealerInfo where "
						+ DatabaseConstants.dealercity + " = '" + searchText
						+ "'";
				System.out.println(sql);
				rs = stmt.executeQuery(sql);
			} else {

				stmt = (Statement) connection.createStatement();
				sql = "select * from dealerInfo where "
						+ DatabaseConstants.dealerdistrict + " = '"
						+ searchText + "'";
				System.out.println(sql);
				rs = stmt.executeQuery(sql);
			}

			// STEP 5: Extract data from result set
			while (rs.next()) {
				// Retrieve by column name
				list.add(rs.getString(DatabaseConstants.dealername));

				hm2.put("dealerData", null);

			}
			rs.close();
			for (int i = 0; i < list.getItemCount(); i++) {
				if (!isDateFieldNull) {
					stmt1 = (Statement) connection.createStatement();
					sql1 = "select * from barcodeFinal where "
							+ DatabaseConstants.barcodeBrokerName + " = '"
							+ list.getItem(i) + "' " + "OR "
							+ DatabaseConstants.barcodeCommisionAgentName
							+ " = '" + list.getItem(i) + "' OR " + ""
							+ DatabaseConstants.barcodecustomerName + " = '"
							+ list.getItem(i) + "' ORDER BY "+DatabaseConstants.barcodedate+" DESC";
					System.out.println(sql1);
					rs1 = stmt.executeQuery(sql1);
				} else if (startDate == 0) {

					stmt1 = (Statement) connection.createStatement();
					sql1 = "select * from barcodeFinal where "
							+ DatabaseConstants.barcodedate + " <= " + endDate
							+ "" + " AND ("
							+ DatabaseConstants.barcodeBrokerName + " = '"
							+ list.getItem(i) + "' " + "OR "
							+ DatabaseConstants.barcodeCommisionAgentName
							+ " = '" + list.getItem(i) + "' OR " + ""
							+ DatabaseConstants.barcodecustomerName + " = '"
							+ list.getItem(i) + "')  ORDER BY "+DatabaseConstants.barcodedate+" DESC";
					System.out.println(sql1);
					rs1 = stmt.executeQuery(sql1);

				} else if (endDate == 0) {

					stmt1 = (Statement) connection.createStatement();
					sql1 = "select * from barcodeFinal where "
							+ DatabaseConstants.barcodedate + " >= "
							+ startDate + "" + " AND ("
							+ DatabaseConstants.barcodeBrokerName + " = '"
							+ list.getItem(i) + "' " + "OR "
							+ DatabaseConstants.barcodeCommisionAgentName
							+ " = '" + list.getItem(i) + "' OR " + ""
							+ DatabaseConstants.barcodecustomerName + " = '"
							+ list.getItem(i) + "')  ORDER BY "+DatabaseConstants.barcodedate+" DESC";
					System.out.println(sql1);
					rs1 = stmt.executeQuery(sql1);

				} else {

					stmt1 = (Statement) connection.createStatement();
					sql1 = "select * from barcodeFinal where ("
							+ DatabaseConstants.barcodedate + " BETWEEN "
							+ startDate + " AND " + endDate + ")" + " AND ("
							+ DatabaseConstants.barcodeBrokerName + " = '"
							+ list.getItem(i) + "' " + "OR "
							+ DatabaseConstants.barcodeCommisionAgentName
							+ " = '" + list.getItem(i) + "' OR " + ""
							+ DatabaseConstants.barcodecustomerName + " = '"
							+ list.getItem(i) + "')  ORDER BY "+DatabaseConstants.barcodedate+" DESC";
					System.out.println(sql1);
					rs1 = stmt.executeQuery(sql1);

				}

				// STEP 5: Extract data from result set
				while (rs1.next()) {
					// Retrieve by column name
					HashMap hm1 = new HashMap();
					hm1.put("businessBrokerName",
							rs1.getString(DatabaseConstants.barcodeBrokerName));
					hm1.put("businesscustomerName", rs1
							.getString(DatabaseConstants.barcodecustomerName));
					hm1.put("businessCommisionAgentName",
							rs1.getString(DatabaseConstants.barcodeCommisionAgentName));
					hm1.put("businessRSTNo",
							rs1.getString(DatabaseConstants.barcodeRstNo));
					hm1.put("businessVehicleNo",
							rs1.getString(DatabaseConstants.barcodeVehicleNo));
					hm1.put("businessCommodity",
							rs1.getString(DatabaseConstants.barcodeCommodity));
					hm1.put("businessNoOfBags",
							rs1.getString(DatabaseConstants.barcodeNoOfBags));
					hm1.put("businessPONo",
							rs1.getString(DatabaseConstants.barcodePONo));
					hm1.put("businessGrossWeight",
							rs1.getString(DatabaseConstants.barcodeGrossWeight));
					hm1.put("businessTareWeight",
							rs1.getString(DatabaseConstants.barcodeTareWeight));
					hm1.put("businessNetWeight",
							rs1.getString(DatabaseConstants.barcodeNetWeight));
					hm1.put("businessdate",
							rs1.getInt(DatabaseConstants.barcodedate));

					hm1.put("businessDamageSeeds",
							rs1.getString(DatabaseConstants.barcodeDamageSeeds));
					hm1.put("businessSandSilica",
							rs1.getString(DatabaseConstants.barcodeSandSilica));
					hm1.put("businessMoisture",
							rs1.getString(DatabaseConstants.barcodeMoisture));
					hm1.put("businessExcessDamage", rs1
							.getString(DatabaseConstants.barcodeExcessDamage));
					hm1.put("businessExcessSandSilica",
							rs1.getString(DatabaseConstants.barcodeExcessSandSilica));
					hm1.put("businessExcessMoisture", rs1
							.getString(DatabaseConstants.barcodeExcessMoisture));
					hm1.put("businessDamageAmountCut",
							rs1.getString(DatabaseConstants.barcodeDamageAmountCut));
					hm1.put("businessSandSilicaAmountCut",
							rs1.getString(DatabaseConstants.barcodeSandSilicaAmountCut));
					hm1.put("businessMoistureAmountCut",
							rs1.getString(DatabaseConstants.barcodeMoistureAmountCut));
					hm1.put("businessUnloading",
							rs1.getString(DatabaseConstants.barcodeUnloading));
					hm1.put("businessAddDalali",
							rs1.getString(DatabaseConstants.barcodeAddDalali));
					hm1.put("businessHide",
							rs1.getString(DatabaseConstants.barcodeHide));

					hm1.put("businessRate",
							rs1.getString(DatabaseConstants.barcodeRate));
					hm1.put("businessGrossAmount",
							rs1.getString(DatabaseConstants.barcodeGrossAmount));
					hm1.put("businessLessRebate",
							rs1.getString(DatabaseConstants.barcodeLessRebate));
					hm1.put("businesscashDiscount", rs1
							.getString(DatabaseConstants.barcodecashDiscount));
					hm1.put("businessAdvance",
							rs1.getString(DatabaseConstants.barcodeAdvance));

					hm1.put("businessTotalRebate",
							rs1.getString(DatabaseConstants.barcodeTotalRebate));
					hm1.put("businessTotalPaid",
							rs1.getString(DatabaseConstants.barcodeTotalPaid));
					hm1.put("businessWeighingMachineUser",
							rs1.getString(DatabaseConstants.barcodeWeighingMachineUser));
					hm1.put("businessLabUser", rs1
							.getString(DatabaseConstants.barcodecashDiscount));

					hm2.put(rs1.getString(DatabaseConstants.barcodeNumber), hm1);
				}
				rs1.close();
			}

		} catch (Exception e) {
			e.printStackTrace();
			return null;

		}

		return hm2;

	}

	public void changeBusinessHidden(String barcode, String status) {
		boolean dataBool = true;
		int response = 0;
		Statement stmt = null;

		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "UPDATE barcodeFinal " + "SET "
					+ DatabaseConstants.barcodeHide + " ='" + status + "'"
					+ " where " + DatabaseConstants.barcodeNumber + " = '"
					+ barcode + "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			// STEP 5: Extract data from result set

			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			System.out.println(dataBool);

		}
		System.out.println(dataBool);

	}

	public boolean update(String barcode, String brockername,
			String customername, String commitionagent, String businessRSTNo,
			String businessVehicle, String businessCommodity,
			String businessNoOfBags, String businessPONo,
			String businessGrossWeight, String businessTareWeight,
			String businessNetWeight, int businessdate, String businessRate,
			String businessGrossAmount, String businessLessRebate,
			String businesscashDiscount, String businessAdvance,
			String businessTotalRebate, String businessTotalPaid,
			String businessWeighingMachineUser, String businessLabUser,
			String businessDamageSeeds, String businessSandSilica,
			String businessMoisture, String businessExcessDamage,
			String businessExcessSandSilica, String businessExcessMoisture,
			String businessDamageAmountCut, String businessSandSilicaAmountCut,
			String businessMoistureAmountCut, String businessUnloading,
			String businessAddDalali, String hide,String address,String time, int operation) {
		boolean dataBool = true;
		
		Statement stmt = null;
		int response = 0, responseInsert = 0;
		Statement stmtInsert = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		if (operation == DatabaseConstants.operation_update) {
			try {
				stmt = (Statement) connection.createStatement();

				String sql = "UPDATE barcodeFinal " + "SET "
						+ DatabaseConstants.barcodeBrokerName + " ='"
						+ brockername.replace(" ", "_") + "', "
						+ DatabaseConstants.barcodecustomerName + " ='"
						+ customername.replace(" ", "_") + "'," + ""
						+ DatabaseConstants.barcodeCommisionAgentName + " ='"
						+ commitionagent.replace(" ", "_") + "', "
						+ DatabaseConstants.barcodeRstNo + " ='"
						+ businessRSTNo + "', "
						+ DatabaseConstants.barcodeVehicleNo + " = '"
						+ businessVehicle + "', " + ""
						+ DatabaseConstants.barcodeCommodity + " ='"
						+ businessCommodity + "', "
						+ DatabaseConstants.barcodeNoOfBags + " ='"
						+ businessNoOfBags + "', " + ""
						+ DatabaseConstants.barcodePONo + " ='" + businessPONo
						+ "', " 
						+ DatabaseConstants.barcodeGrossWeight + " ='"
						+ businessGrossWeight + "', " + ""
						+ DatabaseConstants.barcodeNetWeight + " ='"
						+ businessNetWeight + "', "
						+ DatabaseConstants.barcodeTareWeight + " ='"
						+ businessTareWeight + "', " + ""
						+ DatabaseConstants.barcodedate + " =" + businessdate
						+ ", " + "" + DatabaseConstants.barcodeRate + " ='"
						+ businessRate + "', "
						+ DatabaseConstants.barcodeGrossAmount + " ='"
						+ businessGrossAmount + "', " + ""
						+ DatabaseConstants.barcodeLessRebate + " ='"
						+ businessLessRebate + "', "
						+ DatabaseConstants.barcodecashDiscount + " ='"
						+ businesscashDiscount + "', " + ""
						+ DatabaseConstants.barcodeAdvance + " ='"
						+ businessAdvance + "', "
						+ DatabaseConstants.barcodeTotalRebate + " ='"
						+ businessTotalRebate + "', " + ""
						+ DatabaseConstants.barcodeTotalPaid + " ='"
						+ businessTotalPaid + "', "
						+ DatabaseConstants.barcodeWeighingMachineUser + " ='"
						+ businessWeighingMachineUser + "', " + ""
						+ DatabaseConstants.barcodeLabUser + " ='"
						+ businessLabUser + "', "
						+ DatabaseConstants.barcodeDamageSeeds + " ='"
						+ businessDamageSeeds + "', " + ""
						+ DatabaseConstants.barcodeSandSilica + " ='"
						+ businessSandSilica + "', "
						+ DatabaseConstants.barcodeMoisture + " ='"
						+ businessMoisture + "', " + ""
						+ DatabaseConstants.barcodeExcessDamage + " ='"
						+ businessExcessDamage + "', "
						+ DatabaseConstants.barcodeExcessSandSilica + " ='"
						+ businessExcessSandSilica + "', " + ""
						+ DatabaseConstants.barcodeExcessMoisture + " ='"
						+ businessExcessMoisture + "', "
						+ DatabaseConstants.barcodeDamageAmountCut + " ='"
						+ businessDamageAmountCut + "', " + ""
						+ DatabaseConstants.barcodeSandSilicaAmountCut + " ='"
						+ businessSandSilicaAmountCut + "', "
						+ DatabaseConstants.barcodeMoistureAmountCut + " ='"
						+ businessMoistureAmountCut + "', " + ""
						+ DatabaseConstants.barcodeUnloading + " ='"
						+ businessUnloading + "', "
						+ DatabaseConstants.barcodeAddDalali + " ='"
						+ businessAddDalali + "'" + " where "
						+ DatabaseConstants.barcodeNumber + " = '" + barcode
						+ "'";
				System.out.println(sql);
				response = stmt.executeUpdate(sql);
				// STEP 5: Extract data from result set
				if (response == 0) {
					dataBool = false;
				}

			} catch (Exception e) {
				e.printStackTrace();
				dataBool = false;
				System.out.println(dataBool);
				return dataBool;

			}
			System.out.println(dataBool);
			return dataBool;

		} else {

			try {
				stmtInsert = (Statement) connection.createStatement();

				String sql = "INSERT INTO barcodeFinal " + "VALUES ('" + barcode
						+ "','" + brockername.replace(" ", "_") + "','" + customername.replace(" ", "_") + "','"
						+ commitionagent.replace(" ", "_") + "','"+address+"','" + businessRSTNo + "','"
						+ businessVehicle + "','" + businessCommodity + "',"
						+ "'" + businessNoOfBags + "','" + businessPONo + "','"
						+ businessGrossWeight + "','" + businessTareWeight
						+ "','" + businessNetWeight + "'," + "" + businessdate
						+ ",'"+time+"','" + businessDamageSeeds + "','"
						+ businessSandSilica + "','" + businessMoisture + "','"
						+ businessExcessDamage + "'," + "'"
						+ businessExcessSandSilica + "','"
						+ businessExcessMoisture + "','"
						+ businessDamageAmountCut + "','"
						+ businessSandSilicaAmountCut + "','"
						+ businessMoistureAmountCut + "'," + "'" + businessRate
						+ "','" + businessGrossAmount + "','"
						+ businessLessRebate + "','" + businessUnloading
						+ "','" + businesscashDiscount + "'," + "'"
						+ businessAdvance + "','" + businessAddDalali + "','"
						+ businessTotalRebate + "','" + businessTotalPaid
						+ "','" + hide + "'," + "'"
						+ businessWeighingMachineUser + "','" + businessLabUser
						+ "'" + ")";
				System.out.println(sql);
				responseInsert = stmtInsert.executeUpdate(sql);
				// STEP 5: Extract data from result set
				if (responseInsert == 0) {
					dataBool = false;
				}

			} catch (Exception e) {
				e.printStackTrace();
				dataBool = false;
				System.out.println(dataBool);
				return dataBool;

			}
			System.out.println(dataBool);
			return dataBool;

		}

	}

	public boolean addValue(String barcode, String damage,
			String sandsilica, String moisture, String labuser) {

		boolean dataBool = true;
		int response = 0;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "UPDATE barcodeFinal " + "SET "
					+ DatabaseConstants.barcodeDamageSeeds + " ='"
					+ damage + "', "
					+ DatabaseConstants.barcodeSandSilica + " = '"
					+ sandsilica + "'," + ""
					+ DatabaseConstants.barcodeMoisture + " = '"
					+ moisture + "', " + DatabaseConstants.barcodeLabUser
					+ " = '" + labuser + "'" + " where "
					+ DatabaseConstants.barcodeNumber + " = '" + barcode + "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			// STEP 5: Extract data from result set

			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			System.out.println(dataBool);
			return dataBool;

		}
		System.out.println(dataBool);
		return dataBool;

	}
	
public boolean updateAnalysisReport(String barcode,String pono,String brockername,String commisionAgent,int datebusiness,String partyname,String vehicle,
		String address,String noofbag,String city,String weight,String comodity,String sandActual,String sandDiff,String pricesand,String moistureActual,
		String moistureDiff,String priceSubMoisture,String rate,String damageActual,String damageDiff,String pricesubdamage,String gross,String costunload,
		String lessRebet,String discount,String addDalali,String totalR,String totalRebet,String advance){
	
	boolean dataBool = true;
	int response = 0;
	Statement stmt = null;
	Connection connection = database_connection
			.getConnection(DatabaseConstants.dbName);

	try {
		stmt = (Statement) connection.createStatement();

		String sql = "UPDATE barcodeFinal " + "SET "
				+ DatabaseConstants.barcodePONo + " ='" + pono + "', "
				+ DatabaseConstants.barcodeBrokerName + " = '" + brockername + "',"
				+ DatabaseConstants.barcodeCommisionAgentName + " = '" + commisionAgent + "',"
				+ DatabaseConstants.barcodedate + " =" + datebusiness + ", "
				+ DatabaseConstants.barcodecustomerName + " ='" + partyname + "', "
				+ DatabaseConstants.barcodeVehicleNo + " ='" + vehicle + "', "
				+ DatabaseConstants.barcodeNoOfBags + " ='" + noofbag + "', "
				+ DatabaseConstants.barcodeNetWeight + " ='" + weight + "', "
				
				+ DatabaseConstants.barcodeSandSilica + " ='" + sandActual + "', "
				+ DatabaseConstants.barcodeExcessSandSilica + " = '" + sandDiff + "',"
				+ DatabaseConstants.barcodeSandSilicaAmountCut + " = '" + pricesand + "',"
				+ DatabaseConstants.barcodeMoisture + " =" + moistureActual + ", "
				+ DatabaseConstants.barcodeExcessMoisture + " ='" + moistureDiff + "', "
				+ DatabaseConstants.barcodeMoistureAmountCut + " ='" + priceSubMoisture + "', "
				+ DatabaseConstants.barcodeRate + " ='" + rate + "', "
				+ DatabaseConstants.barcodeDamageSeeds + " ='" + damageActual + "', "
				
				+ DatabaseConstants.barcodeExcessDamage + " ='" + damageDiff + "', "
				+ DatabaseConstants.barcodeDamageAmountCut + " = '" + pricesubdamage + "',"
				+ DatabaseConstants.barcodeGrossAmount + " = '" + gross + "',"
				+ DatabaseConstants.barcodeUnloading + " =" + costunload + ", "
				+ DatabaseConstants.barcodeLessRebate + " ='" + lessRebet + "', "
				+ DatabaseConstants.barcodecashDiscount + " ='" + discount + "', "
				+ DatabaseConstants.barcodeAddDalali + " ='" + addDalali + "', "
				+ DatabaseConstants.barcodeTotalPaid + " ='" + totalR + "', "
				+ DatabaseConstants.barcodeTotalRebate + " ='" + totalRebet + "', "
				+ DatabaseConstants.barcodeAdvance + " ='" + advance + "', "
				+ DatabaseConstants.barcodeCommodity + " ='" + comodity + "' "
				+ " where " + DatabaseConstants.barcodeNumber + " = '"
				+ barcode + "'";
		System.out.println(sql);
		response = stmt.executeUpdate(sql);
		// STEP 5: Extract data from result set

		if (response == 0) {
			dataBool = false;
		}

	} catch (Exception e) {
		e.printStackTrace();
		dataBool = false;
		System.out.println("asdfgh" + dataBool);
		return dataBool;

	}
	System.out.println(dataBool);
	return dataBool;	
	
	
	
}	
	public HashMap getBarcodeInfo(String barcode){
		HashMap hm = new HashMap();
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		Statement stmt = null;
		CommFunction commFunction = new CommFunction();
		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from barcodeFinal where barcodeNumber ='"+barcode+"'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				HashMap hm1 = new HashMap();
				// Retrieve by column name
				hm1.put("businessBrokerName",rs.getString(DatabaseConstants.barcodeBrokerName));
				hm1.put("businesscustomerName", rs.getString(DatabaseConstants.barcodecustomerName));
				hm1.put("businessCommisionAgentName", rs.getString(DatabaseConstants.barcodeCommisionAgentName));
				hm1.put("businessRSTNo", rs.getString(DatabaseConstants.barcodeRstNo));
				hm1.put("businessVehicleNo",rs.getString(DatabaseConstants.barcodeVehicleNo));
				hm1.put("businessCommodity", rs.getString(DatabaseConstants.barcodeCommodity));
				hm1.put("businessNoOfBags",rs.getString(DatabaseConstants.barcodeNoOfBags));
				hm1.put("businessPONo", rs.getString(DatabaseConstants.barcodePONo));
				hm1.put("businessGrossWeight", rs.getString(DatabaseConstants.barcodeGrossWeight));
				hm1.put("businessTareWeight", rs.getString(DatabaseConstants.barcodeTareWeight));
				hm1.put("businessNetWeight", rs.getString(DatabaseConstants.barcodeNetWeight));
				hm1.put("businessdate", commFunction.formatDate(rs.getString(DatabaseConstants.barcodedate)));

				hm1.put("businessRate",rs.getString(DatabaseConstants.barcodeRate));
				hm1.put("businessGrossAmount",rs.getString(DatabaseConstants.barcodeGrossAmount));
				hm1.put("businessLessRebate",rs.getString(DatabaseConstants.barcodeLessRebate));
				hm1.put("businesscashDiscount", rs.getString(DatabaseConstants.barcodecashDiscount));
				hm1.put("businessAdvance", rs.getString(DatabaseConstants.barcodeAdvance));

				hm1.put("businessTotalRebate",rs.getString(DatabaseConstants.barcodeTotalRebate));
				hm1.put("businessTotalPaid",rs.getString(DatabaseConstants.barcodeTotalPaid));
				hm1.put("businessWeighingMachineUser", rs.getString(DatabaseConstants.barcodeWeighingMachineUser));
				hm1.put("businessLabUser", rs.getString(DatabaseConstants.barcodeLabUser));

				hm1.put("businessDamageSeeds", rs.getString(DatabaseConstants.barcodeDamageSeeds));
				hm1.put("businessSandSilica", rs.getString(DatabaseConstants.barcodeSandSilica));
				hm1.put("businessMoisture", rs.getString(DatabaseConstants.barcodeMoisture));
				hm1.put("businessExcessDamage", rs.getString(DatabaseConstants.barcodeExcessDamage));
				hm1.put("businessExcessSandSilica", rs.getString(DatabaseConstants.barcodeExcessSandSilica));
				hm1.put("businessExcessMoisture", rs.getString(DatabaseConstants.barcodeExcessMoisture));
				hm1.put("businessDamageAmountCut",rs.getString(DatabaseConstants.barcodeDamageAmountCut));
				hm1.put("businessSandSilicaAmountCut", rs.getString(DatabaseConstants.barcodeSandSilicaAmountCut));
				hm1.put("businessMoistureAmountCut",rs.getString(DatabaseConstants.barcodeMoistureAmountCut));
				hm1.put("businessUnloading", rs.getString(DatabaseConstants.barcodeUnloading));
				hm1.put("businessAddDalali", rs.getString(DatabaseConstants.barcodeAddDalali));
				hm1.put("businessHide",rs.getString(DatabaseConstants.barcodeHide));
				
				if (rs.getString(DatabaseConstants.barcodecustomerName)!="") {
					Statement stmt1 = null;

					
						stmt1 = (Statement) connection.createStatement();

						String sql1 = "select * from dealerInfo where "+DatabaseConstants.dealername+"='"+rs.getString(DatabaseConstants.barcodecustomerName)+"'";
						System.out.println(sql1);
						ResultSet rs1 = stmt.executeQuery(sql1);
						while (rs1.next()) {
							hm1.put("businessAddress",rs1.getString(DatabaseConstants.dealeraddress));
							hm1.put("businessCity",rs1.getString(DatabaseConstants.dealercity));
						}//rs1.close();
				}else{
					Statement stmt1 = null;

					
					stmt1 = (Statement) connection.createStatement();

					String sql1 = "select * from dealerInfo where "+DatabaseConstants.dealername+"='"+rs.getString(DatabaseConstants.barcodeCommisionAgentName)+"'";
					System.out.println(sql1);
					ResultSet rs1 = stmt.executeQuery(sql1);
					while (rs1.next()) {
						hm1.put("businessAddress",rs1.getString(DatabaseConstants.dealeraddress));
						hm1.put("businessCity",rs1.getString(DatabaseConstants.dealercity));
					}	//rs1.close();
				}
				
				hm.put(barcode, hm1);
				
			}
			//rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return hm;
		}
		
		return hm;
		
	}
	

	// DATABASE FOR barcodeFinalTable functions ends
	// here................................

	// cOMMON FUNCTIONS FOR ALL DATABASE STARTS
	// HERE.......................................

	// cOMMON FUNCTIONS FOR ALL DATABASE ENDS
	// HERE.......................................
	// analysisreporttable and functions starts here..............

	public void createTableAnalysis(Connection connection) {
		String dbName = "parvati_database";
		connection = database_connection.getConnection(dbName);
		String url = DatabaseConstants.DB_URL;
		Statement stmt = null;
		try {
			stmt = (Statement) connection.createStatement();
			System.out.println("statement start");
			String sql = "CREATE TABLE IF NOT EXISTS analysisReportTable" + "("
					+ DatabaseConstants.analysisBarcode + " VARCHAR(255), "
					+ " " + DatabaseConstants.analysisAvailable + " TEXT, "
					+ " CONSTRAINT barcode_constraint UNIQUE ("
					+ DatabaseConstants.analysisBarcode + ")) ";
			System.out.println(sql);
			stmt.executeUpdate(sql);
			System.out.println("table check analysis");

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}// end finally try
	}

	public HashMap getAnalysisList() {
		HashMap hm = new HashMap();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "select * from analysisReportTable";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			// STEP 5: Extract data from result set

			while (rs.next()) {
				// Retrieve by column name
				hm.put(rs.getString(DatabaseConstants.analysisBarcode),
						rs.getString(DatabaseConstants.analysisAvailable));
				System.out.println("get the availability :"
						+ hm.get(rs
								.getString(DatabaseConstants.analysisBarcode)));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
			return hm;

		}

		return hm;
	}

	public boolean deleteAnalysisfromDB(String barcode) {
		boolean dataBool = false;
		int response = 0;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "DELETE FROM analysisReportTable where "
					+ DatabaseConstants.analysisBarcode + " = '" + barcode
					+ "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			return dataBool;

		}
		System.out.println(dataBool);
		return dataBool;

	}

	public boolean updateAnalysisTodb(String barcode) {
		boolean dataBool = true;
		int response = 0;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			stmt = (Statement) connection.createStatement();

			String sql = "UPDATE analysisReportTable " + "SET "
					+ DatabaseConstants.analysisAvailable + " ='Y'" + " where "
					+ DatabaseConstants.analysisBarcode + " = '" + barcode
					+ "'";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			// STEP 5: Extract data from result set

			if (response == 0) {
				dataBool = false;
			}

		} catch (Exception e) {
			e.printStackTrace();
			dataBool = false;
			System.out.println("asdfgh" + dataBool);
			return dataBool;

		}
		System.out.println(dataBool);
		return dataBool;

	}

	public boolean addAnalysisTodb(String barcode) {
		boolean res = true;
		int response = 0;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		Statement stmt = null;
		try {
			stmt = (Statement) connection.createStatement();

			String sql = "INSERT INTO analysisReportTable " + "VALUES ('"
					+ barcode + "','N')";
			System.out.println(sql);
			response = stmt.executeUpdate(sql);
			if (response == 0) {
				res = false;
			}
			System.out.println("data inserted successfully");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			res = false;

			e.printStackTrace();
			return res;
		}
		return res;

	}


	public String getUniquDealerId(String name){
		Statement statement = null;
		String sql = "select * from dealerinfo where "+DatabaseConstants.dealername+"='"+name+"'";
		System.out.println(sql);
		String uniquid = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			statement = (Statement) connection.createStatement();
			ResultSet rs = statement.executeQuery(sql);
			
			while (rs.next()) {
				uniquid = rs.getString(DatabaseConstants.dealerUniqueid);
				System.out.println("Uniquid "+uniquid);
			}
			
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return uniquid;
	}
	
	
	
	public HashMap getBusinessData(){
		HashMap hm= new HashMap();
		List list = new List();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
	stmt = (Statement) connection.createStatement();

	String sql = "select * from barcodeFinal";
	System.out.println(sql);
	ResultSet rs = stmt.executeQuery(sql);
	// STEP 5: Extract data from result set

	HashMap hashMaphead = new HashMap();
	hashMaphead.put("barcodeNumber", (DatabaseConstants.barcodeNumber));
	hashMaphead.put("brokerName", (DatabaseConstants.barcodeBrokerName));
	hashMaphead.put("customerName", (DatabaseConstants.barcodecustomerName));
	
	hashMaphead.put("commisionAgentName", (DatabaseConstants.barcodeCommisionAgentName));
	hashMaphead.put("RSTNO", (DatabaseConstants.barcodeRstNo));
	hashMaphead.put("vehicleNo", (DatabaseConstants.barcodeVehicleNo));
	hashMaphead.put("commodity", (DatabaseConstants.barcodeCommodity));
	hashMaphead.put("NoofBags", (DatabaseConstants.barcodeNoOfBags));
	hashMaphead.put("PONo", (DatabaseConstants.barcodePONo));
	hashMaphead.put("grossWeight", (DatabaseConstants.barcodeGrossWeight));
	hashMaphead.put("tareWeight", (DatabaseConstants.barcodeTareWeight));
	hashMaphead.put("netWeight", (DatabaseConstants.barcodeNetWeight));
	hashMaphead.put("date", (DatabaseConstants.barcodedate));
	hashMaphead.put("sandSilica", (DatabaseConstants.barcodeSandSilica));
	hashMaphead.put("damage", (DatabaseConstants.barcodeDamageSeeds));
	
	hashMaphead.put("moisture", (DatabaseConstants.barcodeMoisture));
	hashMaphead.put("excesSandSilica", (DatabaseConstants.barcodeExcessSandSilica));
	hashMaphead.put("excessDamageSeeds", (DatabaseConstants.barcodeExcessDamage));
	hashMaphead.put("excessMoisture", (DatabaseConstants.barcodeExcessMoisture));
	hashMaphead.put("NoofBags", (DatabaseConstants.barcodeNoOfBags));
	hashMaphead.put("sandSilicaMoistureCut", (DatabaseConstants.barcodeSandSilicaAmountCut));
	hashMaphead.put("damageSeedsAmountCut", (DatabaseConstants.barcodeDamageAmountCut));
	hashMaphead.put("moistureAmountCut", (DatabaseConstants.barcodeMoistureAmountCut));
	hashMaphead.put("rate", (DatabaseConstants.barcodeRate));
	hashMaphead.put("grossAmount", (DatabaseConstants.barcodeGrossAmount));
	hashMaphead.put("lessRebate", (DatabaseConstants.barcodeLessRebate));
	hashMaphead.put("unloading", (DatabaseConstants.barcodeUnloading));
	
	
	hashMaphead.put("cashDiscount", (DatabaseConstants.barcodecashDiscount));
	hashMaphead.put("advance", (DatabaseConstants.barcodeAdvance));
	hashMaphead.put("addDalali", (DatabaseConstants.barcodeAddDalali));
	hashMaphead.put("totalRebate", (DatabaseConstants.barcodeTotalRebate));
	hashMaphead.put("totalTobePaid", (DatabaseConstants.barcodeTotalPaid));
	hashMaphead.put("hide", (DatabaseConstants.barcodeHide));
	hashMaphead.put("weighingMachineUser", (DatabaseConstants.barcodeWeighingMachineUser));
	hashMaphead.put("labuser", (DatabaseConstants.barcodeLabUser));

	hm.put("1", hashMaphead);
	while (rs.next()) {
		// Retrieve by column name
		HashMap hashMap = new HashMap();
		hashMap.put("barcodeNumber", rs.getString(DatabaseConstants.barcodeNumber));
		hashMap.put("brokerName", rs.getString(DatabaseConstants.barcodeBrokerName));
		hashMap.put("customerName", rs.getString(DatabaseConstants.barcodecustomerName));
		
		hashMap.put("commisionAgentName", rs.getString(DatabaseConstants.barcodeCommisionAgentName));
		hashMap.put("RSTNO", rs.getString(DatabaseConstants.barcodeRstNo));
		hashMap.put("vehicleNo", rs.getString(DatabaseConstants.barcodeVehicleNo));
		hashMap.put("commodity", rs.getString(DatabaseConstants.barcodeCommodity));
		hashMap.put("NoofBags", rs.getString(DatabaseConstants.barcodeNoOfBags));
		hashMap.put("PONo", rs.getString(DatabaseConstants.barcodePONo));
		hashMap.put("grossWeight", rs.getString(DatabaseConstants.barcodeGrossWeight));
		hashMap.put("tareWeight", rs.getString(DatabaseConstants.barcodeTareWeight));
		hashMap.put("netWeight", rs.getString(DatabaseConstants.barcodeNetWeight));
		hashMap.put("date", rs.getString(DatabaseConstants.barcodedate));
		hashMap.put("sandSilica", rs.getString(DatabaseConstants.barcodeSandSilica));
		hashMap.put("damage", rs.getString(DatabaseConstants.barcodeDamageSeeds));
		
		hashMap.put("moisture", rs.getString(DatabaseConstants.barcodeMoisture));
		hashMap.put("excesSandSilica", rs.getString(DatabaseConstants.barcodeExcessSandSilica));
		hashMap.put("excessDamageSeeds", rs.getString(DatabaseConstants.barcodeExcessDamage));
		hashMap.put("excessMoisture", rs.getString(DatabaseConstants.barcodeExcessMoisture));
		hashMap.put("NoofBags", rs.getString(DatabaseConstants.barcodeNoOfBags));
		hashMap.put("sandSilicaMoistureCut", rs.getString(DatabaseConstants.barcodeSandSilicaAmountCut));
		hashMap.put("damageSeedsAmountCut", rs.getString(DatabaseConstants.barcodeDamageAmountCut));
		hashMap.put("moistureAmountCut", rs.getString(DatabaseConstants.barcodeMoistureAmountCut));
		hashMap.put("rate", rs.getString(DatabaseConstants.barcodeRate));
		hashMap.put("grossAmount", rs.getString(DatabaseConstants.barcodeGrossAmount));
		hashMap.put("lessRebate", rs.getString(DatabaseConstants.barcodeLessRebate));
		hashMap.put("unloading", rs.getString(DatabaseConstants.barcodeUnloading));
		
		
		hashMap.put("cashDiscount", rs.getString(DatabaseConstants.barcodecashDiscount));
		hashMap.put("advance", rs.getString(DatabaseConstants.barcodeAdvance));
		hashMap.put("addDalali", rs.getString(DatabaseConstants.barcodeAddDalali));
		hashMap.put("totalRebate", rs.getString(DatabaseConstants.barcodeTotalRebate));
		hashMap.put("totalTobePaid", rs.getString(DatabaseConstants.barcodeTotalPaid));
		hashMap.put("hide", rs.getString(DatabaseConstants.barcodeHide));
		hashMap.put("weighingMachineUser", rs.getString(DatabaseConstants.barcodeWeighingMachineUser));
		hashMap.put("labuser", rs.getString(DatabaseConstants.barcodeLabUser));
		
		////////////////////////list can not add hashmap------------------------------------------
		
		hm.put(rs.getString(DatabaseConstants.barcodeNumber), hashMap);
		
	}
	rs.close();
} catch (Exception e) {
	e.printStackTrace();
	return hm;

}		
		return hm;
	}
	
	
	public HashMap getDealerData(){
		HashMap hm= new HashMap();
		List list = new List();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
	stmt = (Statement) connection.createStatement();

	String sql = "select * from dealerInfo";
	System.out.println(sql);
	ResultSet rs = stmt.executeQuery(sql);
	// STEP 5: Extract data from result set

	HashMap hashMapOuter = new HashMap();
	hashMapOuter.put("dealerName", (DatabaseConstants.dealername));
	hashMapOuter.put("dealerRole", (DatabaseConstants.dealerrole));
	hashMapOuter.put("dealeruniqueId", (DatabaseConstants.dealerUniqueid));
	
	hashMapOuter.put("dealerAddress", (DatabaseConstants.dealeraddress));
	hashMapOuter.put("dealerCity", (DatabaseConstants.dealercity));
	hashMapOuter.put("dealerDistrict", (DatabaseConstants.dealerdistrict));
	hashMapOuter.put("dealerState", (DatabaseConstants.dealerstate));
	hashMapOuter.put("dealerCountry", (DatabaseConstants.dealercountry));
	hashMapOuter.put("dealerZipcode", (DatabaseConstants.dealerzipcode));
	hashMapOuter.put("dealerContact", (DatabaseConstants.dealercontact));
	hashMapOuter.put("dealerEmailId", (DatabaseConstants.dealeremailid));
	
	////////////////////////list can not add hashmap------------------------------------------
	hm.put("1", hashMapOuter);
	
	while (rs.next()) {
		// Retrieve by column name
		HashMap hashMap = new HashMap();
		hashMap.put("dealerName", rs.getString(DatabaseConstants.dealername));
		hashMap.put("dealerRole", rs.getString(DatabaseConstants.dealerrole));
		hashMap.put("dealeruniqueId", rs.getString(DatabaseConstants.dealerUniqueid));
		
		hashMap.put("dealerAddress", rs.getString(DatabaseConstants.dealeraddress));
		hashMap.put("dealerCity", rs.getString(DatabaseConstants.dealercity));
		hashMap.put("dealerDistrict", rs.getString(DatabaseConstants.dealerdistrict));
		hashMap.put("dealerState", rs.getString(DatabaseConstants.dealerstate));
		hashMap.put("dealerCountry", rs.getString(DatabaseConstants.dealercountry));
		hashMap.put("dealerZipcode", rs.getString(DatabaseConstants.dealerzipcode));
		hashMap.put("dealerContact", rs.getString(DatabaseConstants.dealercontact));
		hashMap.put("dealerEmailId", rs.getString(DatabaseConstants.dealeremailid));
		
		////////////////////////list can not add hashmap------------------------------------------
		hm.put(rs.getString(DatabaseConstants.dealername), hashMap);
	}
	rs.close();
} catch (Exception e) {
	e.printStackTrace();
	return null;

}		
		return hm;
	}
	
	
	public HashMap getBarcodeData(String barcode){
		HashMap hashMap = new HashMap();
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			
	stmt = (Statement) connection.createStatement();

	String sql = "select * from barcodeFinal where "+DatabaseConstants.barcodeNumber+"='"+barcode+"'";
	System.out.println(sql);
	ResultSet rs = stmt.executeQuery(sql);
	// STEP 5: Extract data from result set

	while (rs.next()) {
		// Retrieve by column name
	
		hashMap.put("barcodeNumber", rs.getString(DatabaseConstants.barcodeNumber));
		hashMap.put("brokerName", rs.getString(DatabaseConstants.barcodeBrokerName));
		hashMap.put("customerName", rs.getString(DatabaseConstants.barcodecustomerName));
		
		hashMap.put("commisionAgentName", rs.getString(DatabaseConstants.barcodeCommisionAgentName));
		hashMap.put("RSTNO", rs.getString(DatabaseConstants.barcodeRstNo));
		hashMap.put("vehicleNo", rs.getString(DatabaseConstants.barcodeVehicleNo));
		hashMap.put("commodity", rs.getString(DatabaseConstants.barcodeCommodity));
		hashMap.put("NoofBags", rs.getString(DatabaseConstants.barcodeNoOfBags));
		hashMap.put("PONo", rs.getString(DatabaseConstants.barcodePONo));
		hashMap.put("grossWeight", rs.getString(DatabaseConstants.barcodeGrossWeight));
		hashMap.put("tareWeight", rs.getString(DatabaseConstants.barcodeTareWeight));
		hashMap.put("netWeight", rs.getString(DatabaseConstants.barcodeNetWeight));
		hashMap.put("date", rs.getString(DatabaseConstants.barcodedate));
		hashMap.put("sandSilica", rs.getString(DatabaseConstants.barcodeSandSilica));
		hashMap.put("damage", rs.getString(DatabaseConstants.barcodeDamageSeeds));
		
		hashMap.put("moisture", rs.getString(DatabaseConstants.barcodeMoisture));
		hashMap.put("excesSandSilica", rs.getString(DatabaseConstants.barcodeExcessSandSilica));
		hashMap.put("excessDamageSeeds", rs.getString(DatabaseConstants.barcodeExcessDamage));
		hashMap.put("excessMoisture", rs.getString(DatabaseConstants.barcodeExcessMoisture));
		hashMap.put("NoofBags", rs.getString(DatabaseConstants.barcodeNoOfBags));
		hashMap.put("sandSilicaMoistureCut", rs.getString(DatabaseConstants.barcodeSandSilicaAmountCut));
		hashMap.put("damageSeedsAmountCut", rs.getString(DatabaseConstants.barcodeDamageAmountCut));
		hashMap.put("moistureAmountCut", rs.getString(DatabaseConstants.barcodeMoistureAmountCut));
		hashMap.put("rate", rs.getString(DatabaseConstants.barcodeRate));
		hashMap.put("grossAmount", rs.getString(DatabaseConstants.barcodeGrossAmount));
		hashMap.put("lessRebate", rs.getString(DatabaseConstants.barcodeLessRebate));
		hashMap.put("unloading", rs.getString(DatabaseConstants.barcodeUnloading));
		
		
		hashMap.put("cashDiscount", rs.getString(DatabaseConstants.barcodecashDiscount));
		hashMap.put("advance", rs.getString(DatabaseConstants.barcodeAdvance));
		hashMap.put("addDalali", rs.getString(DatabaseConstants.barcodeAddDalali));
		hashMap.put("totalRebate", rs.getString(DatabaseConstants.barcodeTotalRebate));
		hashMap.put("totalTobePaid", rs.getString(DatabaseConstants.barcodeTotalPaid));
		hashMap.put("hide", rs.getString(DatabaseConstants.barcodeHide));
		hashMap.put("weighingMachineUser", rs.getString(DatabaseConstants.barcodeWeighingMachineUser));
		hashMap.put("labuser", rs.getString(DatabaseConstants.barcodeLabUser));
		
		////////////////////////list can not add hashmap------------------------------------------
	}
	rs.close();
} catch (Exception e) {
	e.printStackTrace();
	return hashMap;

}		
		return hashMap;
		
	}
	
	
	public HashMap getRSTData(String rstno){
		HashMap hashMap = null;
		Statement stmt = null;
		Connection connection = database_connection
				.getConnection(DatabaseConstants.dbName);

		try {
			
	stmt = (Statement) connection.createStatement();

	String sql = "select * from barcodeFinal where "+DatabaseConstants.barcodeRstNo+"='"+rstno+"'";
	System.out.println(sql);
	ResultSet rs = stmt.executeQuery(sql);
	// STEP 5: Extract data from result set

	while (rs.next()) {
		// Retrieve by column name
		hashMap = new HashMap();
		hashMap.put("barcodeNumber", rs.getString(DatabaseConstants.barcodeNumber));
		hashMap.put("brokerName", rs.getString(DatabaseConstants.barcodeBrokerName));
		hashMap.put("customerName", rs.getString(DatabaseConstants.barcodecustomerName));
		
		//hashMap.put("address", rs.getString(DatabaseConstants.barcode));
		hashMap.put("commisionAgentName", rs.getString(DatabaseConstants.barcodeCommisionAgentName));
		hashMap.put("RSTNO", rs.getString(DatabaseConstants.barcodeRstNo));
		hashMap.put("vehicleNo", rs.getString(DatabaseConstants.barcodeVehicleNo));
		hashMap.put("commodity", rs.getString(DatabaseConstants.barcodeCommodity));
		hashMap.put("NoofBags", rs.getString(DatabaseConstants.barcodeNoOfBags));
		hashMap.put("PONo", rs.getString(DatabaseConstants.barcodePONo));
		hashMap.put("grossWeight", rs.getString(DatabaseConstants.barcodeGrossWeight));
		hashMap.put("tareWeight", rs.getString(DatabaseConstants.barcodeTareWeight));
		hashMap.put("netWeight", rs.getString(DatabaseConstants.barcodeNetWeight));
		hashMap.put("date", rs.getString(DatabaseConstants.barcodedate));
		hashMap.put("sandSilica", rs.getString(DatabaseConstants.barcodeSandSilica));
		hashMap.put("damage", rs.getString(DatabaseConstants.barcodeDamageSeeds));
		
		hashMap.put("time", rs.getString(DatabaseConstants.barcodetime));
		hashMap.put("address", rs.getString(DatabaseConstants.barcodeaddress));
		
		hashMap.put("moisture", rs.getString(DatabaseConstants.barcodeMoisture));
		hashMap.put("excesSandSilica", rs.getString(DatabaseConstants.barcodeExcessSandSilica));
		hashMap.put("excessDamageSeeds", rs.getString(DatabaseConstants.barcodeExcessDamage));
		hashMap.put("excessMoisture", rs.getString(DatabaseConstants.barcodeExcessMoisture));
		hashMap.put("NoofBags", rs.getString(DatabaseConstants.barcodeNoOfBags));
		hashMap.put("sandSilicaMoistureCut", rs.getString(DatabaseConstants.barcodeSandSilicaAmountCut));
		hashMap.put("damageSeedsAmountCut", rs.getString(DatabaseConstants.barcodeDamageAmountCut));
		hashMap.put("moistureAmountCut", rs.getString(DatabaseConstants.barcodeMoistureAmountCut));
		hashMap.put("rate", rs.getString(DatabaseConstants.barcodeRate));
		hashMap.put("grossAmount", rs.getString(DatabaseConstants.barcodeGrossAmount));
		hashMap.put("lessRebate", rs.getString(DatabaseConstants.barcodeLessRebate));
		hashMap.put("unloading", rs.getString(DatabaseConstants.barcodeUnloading));
		
		
		hashMap.put("cashDiscount", rs.getString(DatabaseConstants.barcodecashDiscount));
		hashMap.put("advance", rs.getString(DatabaseConstants.barcodeAdvance));
		hashMap.put("addDalali", rs.getString(DatabaseConstants.barcodeAddDalali));
		hashMap.put("totalRebate", rs.getString(DatabaseConstants.barcodeTotalRebate));
		hashMap.put("totalTobePaid", rs.getString(DatabaseConstants.barcodeTotalPaid));
		hashMap.put("hide", rs.getString(DatabaseConstants.barcodeHide));
		hashMap.put("weighingMachineUser", rs.getString(DatabaseConstants.barcodeWeighingMachineUser));
		hashMap.put("labuser", rs.getString(DatabaseConstants.barcodeLabUser));
		
		////////////////////////list can not add hashmap------------------------------------------
	}
	rs.close();
} catch (Exception e) {
	e.printStackTrace();
	return null;

}		
		return hashMap;
		
	}
	
}
